package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsGrouponRulesMapper;
import com.qf.pojo.DtsGrouponRules;
import com.qf.service.DtsGrouponRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author Cc
 * @version 1.0
 */
@Service

public class DtsGrouponRulesServiceImpl implements DtsGrouponRulesService {

    @Autowired
    private DtsGrouponRulesMapper dtsGrouponRulesMapper;

    @Override
    public IPage<DtsGrouponRules> page(String goodsId, Integer page, Integer limit, String sort, String order) {
        Page<DtsGrouponRules> page1 = new Page<>(page, limit);
        QueryWrapper<DtsGrouponRules> wrapper = new QueryWrapper<>();
        wrapper.like(!StringUtils.isEmpty(goodsId),"goods_id",goodsId)
                .eq("deleted",false)
                .orderBy(!StringUtils.isEmpty(sort),"DESC".equalsIgnoreCase(order),sort);
        if (StringUtils.isEmpty(order)) {
            wrapper.orderByAsc(sort);
        }else {
            wrapper.orderByDesc(sort);
        }

        Page<DtsGrouponRules> rulesPage = dtsGrouponRulesMapper.selectPage(page1, wrapper);

        return rulesPage;
    }

    @Override
    public void add(DtsGrouponRules grouponRules) {
        dtsGrouponRulesMapper.insert(grouponRules);
    }

    @Override
    public void deleteGrouponRules(Integer id) {
        dtsGrouponRulesMapper.deleteUpdateById(id);
    }
}

